import mx.utils.Delegate;
dynamic class RotateModul extends MovieClip{
	private var $centerx:Number=0;
	private var $centery:Number=0;
	private var $centerZ:Number=0;
	private var $r:Number=100;
	private var $angle:Number=0;
	private var $viewPointY:Number=0;
	private var $viewPointZ:Number=1;
	private var $rtMc:MovieClip;
	private var $project:Number=200;
	private var $maxScale:Number=500;
	private var $root:MovieClip;
	private var $yScale:Number=1.0;
	public function get YScale():Number{
		return this.$yScale;
	}
	public function set YScale(value:Number){
		this.$yScale=value;
	}
	
	public function get Angle():Number{
		return this.$angle;
	}
	public function set Angle(value:Number){
		this.$angle=value;
	}
	
	public function get MaxScale():Number{
		return this.$maxScale;
	}
	public function set MaxScale(value:Number){
		this.$maxScale=value;
	}
	
	public function get Project():Number{
		return this.$project;
	}
	public function set Project(value:Number){
		this.$project=value;
	}
	
	public function get ViewPointY():Number{
		return this.$viewPointY;
	}
	public function set ViewPointY(value:Number){
		this.$viewPointY=value;
	}
	
	public function get ViewPointZ():Number{
		return this.$viewPointZ;
	}
	public function set ViewPointZ(value:Number){
		this.$viewPointZ=value;
	}
	
	public function get CenterX():Number{
		return this.$centerx;
	}
	public function set CenterX(value:Number){
		this.$centerx=value;
	}
	
	public function get CenterY():Number{
		return this.$centery;
	}
	public function set CenterY(value:Number){
		this.$centery=value;
	}
	
	public function get CenterZ():Number{
		return this.$centerZ;
	}
	public function set CenterZ(value:Number){
		this.$centerZ=value;
	}
	
	public function get R():Number{
		return this.$r;
	}
	public function set R(value:Number){
		this.$r=value;
	}
	
	public function RotateModul(mc:MovieClip,r:Number,angle:Number){
		if(mc==undefined){
			mc=this;
		}
		this.$root=mc;
		if(r!=undefined){
			this.$r=r;
		}
		if(angle!=undefined){
			this.$angle=angle;
		}
	}
	public function startRotate(){
		this.$rtMc=this.$root.createEmptyMovieClip("__rotateMc",1000000);
		this.$rtMc.onEnterFrame=Delegate.create(this,this.rofun);
	}
	public function stopRotate(){
		this.$rtMc.removeMovieClip();
	}
	private function rofun(){

		var px:Number=this.$centerx+this.$r*Math.cos(this.$angle);
		var pz:Number=this.$centerZ+this.$r*Math.sin(this.$angle);
		var yl:Number=this.$centery-this.$viewPointY;
		var py:Number=this.$centery-yl*Math.sin(this.$angle);
		var zl:Number=this.$viewPointZ-pz;
		
		if(zl>this.$project){
			this.$root._xscale=this.$root._yscale=0;
			return;
		}
		if(zl<0){
			this.$root._visible=false;
		}else{
			this.$root._visible=true;
		}
		
		var bl:Number=(this.$project-zl)/this.$project;
		var scale:Number=bl*this.$maxScale;
		yl*=bl;
		px*=bl;
		
		
		this.$root._x=px;
		this.$root._y=(yl)*this.$yScale;
		this.$root._z=pz;
		this.$root._xscale=this.$root._yscale=scale;
		
	}
}





















